import axios from "axios";
import {getToken} from "@/utils/Token";
import { Message } from 'element-ui'



const service = axios.create({
        baseURL:'http://localhost:9504',//baseURL会自动加在请求地址上
        timeout: 3000,
})


//添加请求拦截器
service.interceptors.request.use((config)=>{
    //在请求之前做些什么
    if(getToken('token') != null){
        config.headers.Authorization = getToken('token')
    }
    return config
},(error) => {
    return Promise.reject(error)
})
// 添加响应拦截器
service.interceptors.response.use((response)=>{
    //对于响应数据做些什么
    let {state, message} = response.data
    if(state !== 200){
        // Message({message: message||'error',type:'warning'})
        console.log(response.data)
    }else {
    }
    console.log(response.data)
    return response
},(error) => {
    return Promise.reject(error)
})

export default service;
